package locations.dao.implement;

import java.util.List;
import locations.dao.InstitutionResponsibleDAO;
import locations.model.InstitutionResponsible;

public class InstitutionResponsibleDAOHibernateJPA extends GenericDAOHibernateJPA<InstitutionResponsible>
	implements
		InstitutionResponsibleDAO {

	public InstitutionResponsibleDAOHibernateJPA() {
		super(InstitutionResponsible.class);
	
	}

    @Override
    public boolean exists(String name, String lastName, long id)
    {
        boolean started = this.getTransaction().isActive();
        if (!started)
        {
            this.getTransaction().begin();            
        }
        String queryId = (id == 0 ? "" :  " and i.id !='" + id + "'");
        List result= entityManager.createQuery
                ("from InstitutionResponsible i where i.nombre='" + name + "' and i.apellido ='"
                + lastName + "' " + queryId).getResultList();
//            this.getTransaction().commit();            
        return ! result.isEmpty();
    }
	



	
	
}